package com.briup.recognition.web.controller;


import com.briup.recognition.bean.GreenhouseMessage;
import com.briup.recognition.bean.Module;
import com.briup.recognition.service.IModuleService;
import com.briup.recognition.utils.Message;
import com.briup.recognition.utils.MessageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/module")
public class ModuleController {
    @Autowired
    private IModuleService iModuleService;

    @GetMapping("query")
    public Message query(){
       return MessageUtil.success(
                iModuleService.query()
        );
    }

    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Module module){
        if (module.getId() == null){
            module.setCreateTime(new Date().getTime());
            iModuleService.saveOrUpdate(module);
            return MessageUtil.success(
                    "插入成功！"
            );
        } else {
            iModuleService.saveOrUpdate(module);
            return MessageUtil.success(
                    "更新成功！"
            );
        }
    }

    @DeleteMapping("deleteById")
    public Message deleteById(Long id){
        iModuleService.deleteById(id);
        return MessageUtil.success(
                "删除成功！"
        );
    }

}
